
import axios from 'axios';
import state from 'store/type-state/state_1'
function PublicHttp(flag=false){
	return (!flag)?'http://192.168.3.237:5001':'' ;
}


function checkStatus(response) {
    if (response.status >= 200 && response.status < 300) {
        return response
    } else {
        var error = new Error(response.statusText);
        error.response = response;
        throw error
    }
}


function GetDatasdes(opt){
	if(opt.type == 'get'){
            console.log(opt.param)
            console.log(opt.type)
            console.log(opt.url)
        axios({
            url:PublicHttp(false)+opt.url,
            method:opt.type || 'get',
            headers:{'Content-Type':opt.contentType || 'application/json'},
            // headers:{'Authorization':'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhcGkiLCJpc3MiOiJSdWlZaW5Db3JlIiwiaWQiOiIwMmI0YTFlMS04ZmI0LTQ4OGEtOGJjNS0zZTg2OGY5YWNjMDMiLCJuYW1lIjoi5a6i5oi3IiwiZW1haWwiOiI5NDQwODEwMTlAcXEuY29tIiwicGhvbmVfbnVtYmVyIjoiMTM4ODIxOTgzNzUiLCJuYmYiOjE1Mjc0NjkzMzAsImV4cCI6MTUyODA3NDEzMCwiaWF0IjoxNTI3NDY5MzMwfQ.FJkz5Tz_COoowCKvO9F29tQJrUSNmBmKdprhBZt9fFU'},
            params:opt.param,
        }).then(function (response) {
            return response
        }).then(checkStatus)
            .then(function (response) {
                return response['data'];
            }).then(function(data) {
            opt.success(data)
        }).catch(function(err) {
            opt.error(err)
        })

	}else {
        axios({
            url:PublicHttp(false)+opt.url,
            method:opt.type || 'POST',
            headers:{'Content-Type':opt.contentType || 'application/json'},
            data:opt.param,
            headers:{'Authorization':'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhcGkiLCJpc3MiOiJSdWlZaW5Db3JlIiwiaWQiOiIwMmI0YTFlMS04ZmI0LTQ4OGEtOGJjNS0zZTg2OGY5YWNjMDMiLCJuYW1lIjoi5a6i5oi3IiwiZW1haWwiOiI5NDQwODEwMTlAcXEuY29tIiwicGhvbmVfbnVtYmVyIjoiMTM4ODIxOTgzNzUiLCJuYmYiOjE1Mjc0NjkzMzAsImV4cCI6MTUyODA3NDEzMCwiaWF0IjoxNTI3NDY5MzMwfQ.FJkz5Tz_COoowCKvO9F29tQJrUSNmBmKdprhBZt9fFU'}
        }).then(function (response) {
            return response
        }).then(checkStatus)
            .then(function (response) {
                return response['data'];
            }).then(function(data) {
            opt.success(data)
        }).catch(function(err) {
            opt.error(err)
        })
	}





  /*fetch(HttpUrl+opt.url,{
   method:opt.type || 'POST',
   headers:{'Content-Type':opt.contentType || 'application/json', 'RandNum':r, 'TimeStamp':rr, 'Parameter':rrr},
   // body:JSON.stringify(opt.param)
   body:data
   })
   .then(DAes)
   .then(checkStatus)
   .then(parseJSON)
   .then(function(data) {
   console.log(data)
   if(data["Result"]){
   opt.success(data)
   }else{
   // console.log("获取数据失败")
   opt.error(data)
   }
   }).catch(function(err) {
   // console.log("获取数据失败")
   opt.error(err)
   })*/
}

export {
  PublicHttp,
  GetDatasdes
}







